#!/bin/bash

dist='dist'

rm -rf $dist
mkdir $dist

tsc --outDir $dist

# 生成 icon
node build-icon.js

cp -r public/* $dist

# 生成 stylus -> css 的文件到 dist 文件夹中
node build-css.js

current_path=$(pwd)
echo "$current_path"
temp="${current_path}/temp"
mkdir "$temp"
cd "$temp" || exit
packageJson='{
                "name"           : "utools-recent-projects-dependencies",
                "version"        : "1.0.0",
                "license"        : "MIT",
                "dependencies"   : {
                  "bplist-parser"    : "^0.3.2",
                  "licia"            : "^1.46.0",
                  "nano-jsx"         : "^0.1.0",
                  "pinyinlite"       : "^1.2.1",
                  "string-comparison": "^1.3.0",
                  "winreg"           : "^1.2.5"
                }
              }'
echo "$packageJson" > package.json
npm i
npm cache clean --force

cd "${temp}/node_modules/licia" || exit
rm -rf *.ts *.md
cd "$temp" || exit

cd "${temp}/node_modules/nano-jsx" || exit
rm -rf esm .vscode readme .eslintrc .prettierrc bundles typings *.tsx jest*.json tsconfig*.json LICENSE *.md .npmrc
find lib -name '*.ts' | xargs rm -rf
find lib -name '*.map' | xargs rm -rf
cd "$temp" || exit

cd "${temp}/node_modules/big-integer" || exit
rm -rf *.md *.ts tsconfig*.json LICENSE bower.json BigInteger.js
mv BigInteger.min.js BigInteger.js
cd "$temp" || exit

cd "${temp}/node_modules/bplist-parser" || exit
rm -rf *.md .editorconfig .eslintignore .eslintrc.js *.d.ts
cd "$temp" || exit

cd "${temp}/node_modules/winreg" || exit
rm -rf test *.md .npmignore jsdoc.conf.json
cd "$temp" || exit

cd "${temp}/node_modules/pinyinlite" || exit
rm -rf dist examples .npmignore *.md LICENSE bower.json
cd "$temp" || exit

cd "${temp}/node_modules/string-comparison" || exit
rm -rf LICENCE *.md dist/*.d.ts dist/*.mjs
cd "$temp" || exit

cd "$current_path" || exit
cp -r "${temp}/node_modules" $dist/
rm -rf "$temp"
